package com.android.core.utils.glide;

import android.content.Context;
import android.widget.ImageView;

import com.aidabaobei.core.R;
import com.bumptech.glide.DrawableRequestBuilder;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

import java.io.File;

public class GlideImgManager {

    public static void loadImage(Context context, String url, int erroImg, int emptyImg, ImageView iv) {
        //原生 API  
        Glide.with(context).load(url).placeholder(emptyImg).error(erroImg).into(iv);
    }

    public static void loadImage(Context context, String url, ImageView iv) {
        //原生 API  
        Glide.with(context).load(url).crossFade().placeholder(R.mipmap.em_empty_photo).error(R.mipmap.em_empty_photo).into(iv);
    }

    public static void loadImage(Context context, String url, ImageView iv, boolean isFitCenter) {
        //原生 API
        DrawableRequestBuilder<String> builder = Glide.with(context).load(url).fitCenter().crossFade()
                .placeholder(R.mipmap.em_empty_photo).error(R.mipmap.em_empty_photo).dontAnimate();
        if (isFitCenter) {
            builder.fitCenter().into(iv);
        } else {
            builder.centerCrop().into(iv);
        }
    }

    public static void loadGifImage(Context context, String url, ImageView iv) {
        Glide.with(context).load(url).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).placeholder(R.mipmap.em_empty_photo).error(R.mipmap.em_empty_photo).into(iv);
    }


    public static void loadCircleImage(Context context, String url, ImageView iv) {
        Glide.with(context).load(url).placeholder(R.mipmap.em_empty_photo).error(R.mipmap.em_empty_photo).transform(new GlideCircleTransform(context)).into(iv);
    }

    public static void loadRoundCornerImage(Context context, String url, ImageView iv) {
        Glide.with(context).load(url).placeholder(R.mipmap.em_empty_photo).error(R.mipmap.em_empty_photo).transform(new GlideRoundTransform(context, 10)).into(iv);
    }


    public static void loadImage(Context context, final File file, final ImageView imageView) {
        Glide.with(context)
                .load(file)
                .into(imageView);


    }

    public static void loadImage(Context context, final int resourceId, final ImageView imageView) {
        Glide.with(context)
                .load(resourceId)
                .into(imageView);
    }
}  